﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.CustomerSupplier;
using ERP.Domain.SalesManagement;
using MediatR;
using Sell.Api.Write.Application.Command.ContractCommand;
using Sell.Services.Contracts;

namespace Sell.Api.Write.Application.CommandHandlers.ContractCommandHandlers
{
    public class ContractUpdateCommandHandlers : IRequestHandler<ContractUpdateCommand, ApiResult<int>>
    {
        public IMapper Mapper { get; }
        public IContractServices services { get; }
        public ContractUpdateCommandHandlers(IContractServices _services, IMapper _Mapper)
        {
            Mapper = _Mapper;
            services = _services;
        }
        /// <summary>
        /// 修改采购合同
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<int>> Handle(ContractUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<Contract>(request);
            return await services.UpdateContract(list);
        }
    }
}
